var cheerio = require('cheerio')

module.exports = {
  // 获取每页列表中的topicUrls
  getTopicUrls (html) {
    let topicUrls = []
    let $ = cheerio.load(html)

    $('td.title a').each(function (index, value) {
      let $element = $(value)
      let href = $element.attr('href')
      if (topicUrls.indexOf(href) < 0) {
        topicUrls.push(href)
      }
    })

    return topicUrls
  },

  // 获取每个topicUrl的内容
  getTopicInfo (html, url) {
    let rentHouseInfo = {}
    let $ = cheerio.load(html)

    rentHouseInfo.title = $('tr .tablecc').text()
    let str = $('#content .color-green').text().replace('/-/g', '/')
    let oDate = new Date(str)
    rentHouseInfo.publicData = oDate.getTime()
    rentHouseInfo.topicUrl = url
    rentHouseInfo.isExist = true

    return rentHouseInfo
  }
}
